package mipushdemo.xiaomi.com.diyitonghang.model.impl.loginimpl;

import android.util.Log;

import java.io.IOException;
import java.util.List;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import mipushdemo.xiaomi.com.diyitonghang.api.ApiService;
import mipushdemo.xiaomi.com.diyitonghang.data.bean.NewsChannelData;
import mipushdemo.xiaomi.com.diyitonghang.model.imodel.loginmodel.IHomeModel;
import mipushdemo.xiaomi.com.diyitonghang.utils.RetrofitUtils;
import okhttp3.ResponseBody;

public class HomeModelImpl implements IHomeModel{
    @Override
    public void responseDataMa(String header, final SetOnDataChangedListener listener) {
        ApiService apiService = RetrofitUtils.newInstance().netWorkRequest();
        Observable<NewsChannelData> observable = apiService.homeType(header);
        observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NewsChannelData>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NewsChannelData newsChannelData) {
                        List<NewsChannelData.DataBean.NewsChannelListBean> newsChannelList = newsChannelData.getData().getNewsChannelList();
                        listener.setOnData(newsChannelList);
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
